cmake_minimum_required(VERSION 3.28.3)
project(imos_app_server VERSION 1.0 DESCRIPTION "简单实例" LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(MAIN_SOURCE main.cpp)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output/bin)

add_subdirectory(calculate)
add_subdirectory(message)
add_subdirectory(processor)

file(GLOB ALL_LIBS
        "./lib/self/*.so"          # Linux共享库
)

aux_source_directory(working MODULE_SOURCES)
aux_source_directory(working2 MODULE_SOURCES)

#add_executable(imos_app_server ${MAIN_SOURCE} working/working.cpp)
add_executable(imos_app_server ${MAIN_SOURCE} ${MODULE_SOURCES})

target_link_libraries(imos_app_server PRIVATE ${ALL_LIBS})

# 添加头文件搜索路径
target_include_directories(imos_app_server PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# 根据平台设置不同的库文件名
if (WIN32)
    set(SUPER_HELLO_LIB_NAME super_hello)
else()
    set(SUPER_HELLO_LIB_NAME super_hello)
endif()

# 查找库文件
find_library(SUPER_HELLO_LIB
        NAMES ${SUPER_HELLO_LIB_NAME}
        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/self
        NO_DEFAULT_PATH  # 只在指定路径中查找，不搜索系统路径
)

find_library(XXX_LIB
        NAMES xxx
        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/self
        NO_DEFAULT_PATH
)

find_library(YYY_LIB
        NAMES yyy
        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/self
        NO_DEFAULT_PATH
)

# 检查是否找到库
if (NOT SUPER_HELLO_LIB)
    message(FATAL_ERROR "super_hello library not found!")
endif()

message(STATUS "Found super_hello library: ${SUPER_HELLO_LIB}")

target_link_libraries(imos_app_server PRIVATE
        calculate_lib
        message_lib
        processor_lib
        ${ALL_LIBS}
)
